import { request } from '../request';

/**
 * Login
 *
 * @param userName User name
 * @param password Password
 */
export function fetchLogin(userName: string, password: string) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/login',
    method: 'post',
    data: {
      userName,
      password
    }
  });
}

/** Get user info */
export function fetchGetUserInfo() {
  return request<Api.Auth.UserInfo>({ url: '/auth/getUserInfo' });
}

/**
 * Refresh token
 *
 * @param refreshToken Refresh token
 */
export function fetchRefreshToken(refreshToken: string) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/refreshToken',
    method: 'post',
    data: {
      refreshToken
    }
  });
}

/**
 * return custom backend error
 *
 * @param code error code
 * @param msg error message
 */
export function fetchCustomBackendError(code: string, msg: string) {
  return request({ url: '/auth/error', params: { code, msg } });
}


// 基础路径
const baseUrl = '/user';

/**
 * 分页查询用户接口
 * @param params
 */
export function userPage(params?: Api.SystemManage.SearchUserParam) {
  return request<Api.SystemManage.UserList>({
    url: `${baseUrl}/page`,
    method: 'post',
    params
  });
}

/**
 * 获取用户详情接口
 */
export function userDetail(id: number) {
  return request<Api.SystemManage.UserInfo>({
    url: `${baseUrl}/detail?id=${id}`,
    method: `get`,
  })
}

/**
 * 删除用户接口
 */
export function userDelete(data: Api.Common.DeleteParams[]) {
  return request({
    url: `${baseUrl}/delete`,
    method: `post`,
    data
  })
}
